home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JDialog.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  32.9 KB  |  1,049 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JDialog.java    1.36 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package javax.swing;
  15.  
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import java.beans.PropertyChangeListener;
  19. import java.util.Locale;
  20. import java.util.Vector;
  21. import java.io.Serializable;
  22. import javax.accessibility.*;
  23. import java.applet.Applet;
  24.  
  25. /** 
  26.  * The main class for creating a dialog window. You can use this class
  27.  * to create a custom dialog, or invoke the many static methods
  28.  * in JOptionPane to create a variety of standard dialogs.
  29.  *
  30.  * The JDialog component contains a JRootPane as it's only 
  31.  * child.
  32.  * The <code>contentPane</code> should be the parent of any children of 
  33.  * the JDialog. From the older <code>java.awt.Window</code> object you 
  34.  * would normally do something like this:
  35.  * <PRE>
  36.  *       dialog.add(child);
  37.  * </PRE>
  38.  * Using JDialog the proper semantic is:
  39.  * <PRE>
  40.  *       dialog.getContentPane().add(child);
  41.  * </PRE>
  42.  * The same priniciple holds true for setting layout managers, removing 
  43.  * components, listing children, etc. All these methods should normally 
  44.  * be sent to the <code>contentPane</code> instead of to the JDialog.
  45.  * The <code>contentPane</code> is always non-null. Attempting to set it 
  46.  * to null generates an exception. The default <code>contentPane</code> 
  47.  * has a BorderLayout manager set on it. 
  48.  * <p>
  49.  * Please see the JRootPane documentation for a complete 
  50.  * description of the <code>contentPane</code>, <code>glassPane</code>, 
  51.  * and <code>layeredPane</code> components.
  52.  * <p>
  53.  * NOTE: For 1.1, Modal dialogs are currently constrained to only allow
  54.  * lightweight popup menus (JPopupMenu, JComboBox, JMenuBar) because
  55.  * of window ownership limitations in AWT1.1.   This creates the further
  56.  * limitation of not being able to mix Swing popup components with
  57.  * AWT heavyweight components in a modal dialog since the heavyweight
  58.  * components would always overlap the lightweights, potentially
  59.  * obscuring the popup menu.
  60.  * (A heavyweight component uses a native-platform component (peer)
  61.  * component for its implementation -- AWT components are heavyweight
  62.  * components.)
  63.  * <p>
  64.  * For the keyboard keys used by this component in the standard Look and
  65.  * Feel (L&F) renditions, see the
  66.  * <a href="doc-files/Key-Index.html#JDialog">JDialog</a> key assignments.
  67.  * <p>
  68.  * <strong>Warning:</strong>
  69.  * Serialized objects of this class will not be compatible with 
  70.  * future Swing releases.  The current serialization support is appropriate
  71.  * for short term storage or RMI between applications running the same
  72.  * version of Swing.  A future release of Swing will provide support for
  73.  * long term persistence.
  74.  *
  75.  * @see JOptionPane
  76.  * @see JRootPane
  77.  *
  78.  * @beaninfo
  79.  *      attribute: isContainer true
  80.  *      attribute: containerDelegate getContentPane
  81.  *    description: A toplevel window for creating dialog boxes.
  82.  *
  83.  * @version 1.36 08/28/98
  84.  * @author David Kloba
  85.  * @author James Gosling
  86.  * @author Scott Violet
  87.  */
  88. public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer 
  89. {
  90.     private int defaultCloseOperation = HIDE_ON_CLOSE;
  91.     
  92.     /**
  93.      * @see #getRootPane
  94.      * @see #setRootPane
  95.      */
  96.     protected JRootPane rootPane;
  97.  
  98.     /**
  99.      * @see #isRootPaneCheckingEnabled
  100.      * @see #setRootPaneCheckingEnabled
  101.      */
  102.     protected boolean rootPaneCheckingEnabled = false;
  103.  
  104.  
  105.     /**
  106.      * Creates a non-modal dialog without a title and without
  107.      * a specified Frame owner.  A shared, hidden frame will be
  108.      * set as the owner of the Dialog.
  109.      */
  110.     public JDialog() {
  111.         this((Frame)null, false);
  112.     }
  113.  
  114.     /**
  115.      * Creates a non-modal dialog without a title with the
  116.      * specifed Frame as its owner.
  117.      *
  118.      * @param owner the Frame from which the dialog is displayed
  119.      */
  120.     public JDialog(Frame owner) {
  121.         this(owner, false);
  122.     }
  123.  
  124.     /**
  125.      * Creates a modal or non-modal dialog without a title and
  126.      * with the specified owner frame.
  127.      *
  128.      * @param owner the Frame from which the dialog is displayed
  129.      * @param modal  true for a modal dialog, false for one that allows
  130.      *               others windows to be active at the same time
  131.      */
  132.     public JDialog(Frame owner, boolean modal) {
  133.         this(owner, null, modal);
  134.     }
  135.  
  136.     /**
  137.      * Creates a non-modal dialog with the specified title and
  138.      * with the specified owner frame.
  139.      *
  140.      * @param owner the Frame from which the dialog is displayed
  141.      * @param title  the String to display in the dialog's title bar
  142.      */
  143.     public JDialog(Frame owner, String title) {
  144.         this(owner, title, false);     
  145.     }
  146.  
  147.     /**
  148.      * Creates a modal or non-modal dialog with the specified title 
  149.      * and the specified owner frame.
  150.      * <p>
  151.      * NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar)
  152.      * created within a modal dialog will be forced to be lightweight.
  153.      *
  154.      * @param owner the frame from which the dialog is displayed
  155.      * @param title  the String to display in the dialog's title bar
  156.      * @param modal  true for a modal dialog, false for one that allows
  157.      *               others windows to be active at the same time
  158.      */
  159.     public JDialog(Frame owner, String title, boolean modal) {
  160.         super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner, 
  161.               title, modal);
  162.         dialogInit();
  163.     }
  164.  
  165.     /**
  166.      * Creates a non-modal dialog without a title with the
  167.      * specifed Dialog as its owner.
  168.      *
  169.      * @param owner the Dialog from which the dialog is displayed
  170.      */
  171.  
  172.     public JDialog(Dialog owner) {
  173.         this(owner, false);
  174.     }
  175.   
  176.  
  177.     /**
  178.      * Creates a modal or non-modal dialog without a title and
  179.      * with the specified owner dialog.
  180.      * <p>
  181.      *
  182.      * @param owner the Dialog from which the dialog is displayed
  183.      * @param modal  true for a modal dialog, false for one that allows
  184.      *               others windows to be active at the same time
  185.      */
  186.  
  187.     public JDialog(Dialog owner, boolean modal) {
  188.         this(owner, null, modal);
  189.     }
  190.   
  191.  
  192.     /**
  193.      * Creates a non-modal dialog with the specified title and
  194.      * with the specified owner dialog.
  195.      *
  196.      * @param owner the Dialog from which the dialog is displayed
  197.      * @param title  the String to display in the dialog's title bar
  198.      */
  199.  
  200.     public JDialog(Dialog owner, String title) {
  201.         this(owner, title, false);     
  202.     }
  203.   
  204.  
  205.     /**
  206.      * Creates a modal or non-modal dialog with the specified title 
  207.      * and the specified owner frame.
  208.      *
  209.      * @param owner the dialog from which the dialog is displayed
  210.      * @param title  the String to display in the dialog's title bar
  211.      * @param modal  true for a modal dialog, false for one that allows
  212.      *               others windows to be active at the same time
  213.      */
  214.  
  215.     public JDialog(Dialog owner, String title, boolean modal) {
  216.         super(owner, title, modal);
  217.         dialogInit();
  218.     }
  219.   
  220.  
  221.  
  222.     /** Called by the constructors to init the JDialog properly. */
  223.     protected void dialogInit() {
  224.         enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  225.         setRootPane(createRootPane());
  226.         setRootPaneCheckingEnabled(true);
  227.     }
  228.  
  229.     /** Called by the constructor methods to create the default rootPane. */
  230.     protected JRootPane createRootPane() {
  231.         return new JRootPane();
  232.     }
  233.  
  234.     /**
  235.      * Handles window events depending on the state of the
  236.      * <code>defaultCloseOperation</code> property.
  237.      *
  238.      * @see #setDefaultCloseOperation
  239.      */
  240.     protected void processWindowEvent(WindowEvent e) {
  241.         super.processWindowEvent(e);
  242.  
  243.         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  244.             switch(defaultCloseOperation) {
  245.               case HIDE_ON_CLOSE:
  246.                  setVisible(false);
  247.                  break;
  248.               case DISPOSE_ON_CLOSE:
  249.                  setVisible(false);
  250.                  dispose();
  251.                  break;
  252.               case DO_NOTHING_ON_CLOSE:
  253.                  default: 
  254.                  break;
  255.             }
  256.         }
  257.     }
  258.  
  259.  
  260.     /**
  261.      * Sets the operation which will happen by default when
  262.      * the user initiates a "close" on this dialog.
  263.      * The possible choices are:
  264.      * <ul>
  265.      * <li>DO_NOTHING_ON_CLOSE - do not do anything - require the
  266.      * program to handle the operation in the windowClosing
  267.      * method of a registered WindowListener object.
  268.      * <li>HIDE_ON_CLOSE - automatically hide the dialog after
  269.      * invoking any registered WindowListener objects
  270.      * <li>DISPOSE_ON_CLOSE - automatically hide and dispose the 
  271.      * dialog after invoking any registered WindowListener objects
  272.      * </ul>
  273.      * <p>
  274.      * The value is set to HIDE_ON_CLOSE by default.
  275.      * @see #addWindowListener
  276.      * @see #getDefaultCloseOperation
  277.      *
  278.      * @beaninfo
  279.      *   preferred: true
  280.      * description: The dialog's default close operation.
  281.      */
  282.     public void setDefaultCloseOperation(int operation) {
  283.         this.defaultCloseOperation = operation;
  284.     }
  285.  
  286.    /**
  287.     * Returns the operation which occurs when the user
  288.     * initiates a "close" on this dialog.
  289.     *
  290.     * @return an int indicating the window-close operation
  291.     * @see #setDefaultCloseOperation
  292.     */
  293.     public int getDefaultCloseOperation() {
  294.         return defaultCloseOperation;
  295.     }
  296.  
  297.  
  298.     /** 
  299.      * Just calls <code>paint(g)</code>.  This method was overridden to 
  300.      * prevent an unneccessary call to clear the background.
  301.      */
  302.     public void update(Graphics g) {
  303.         paint(g);
  304.     }
  305.  
  306.    /**
  307.     * Sets the menubar for this dialog.
  308.     * @param menubar the menubar being placed in the dialog
  309.     *
  310.     * @see #getJMenuBar
  311.     *
  312.     * @beaninfo
  313.     *      hidden: true
  314.     * description: The menubar for accessing pulldown menus from this dialog.
  315.     */
  316.     public void setJMenuBar(JMenuBar menu) {
  317.         getRootPane().setMenuBar(menu);
  318.     }
  319.  
  320.    /**
  321.     * Returns the menubar set on this dialog.
  322.     *
  323.     * @see #setJMenuBar
  324.     */
  325.     public JMenuBar getJMenuBar() { 
  326.         return getRootPane().getMenuBar(); 
  327.     }
  328.  
  329.  
  330.     /**
  331.      * @return true if add and setLayout should be checked
  332.      * @see #addImpl
  333.      * @see #setLayout
  334.      * @see #setRootPaneCheckingEnabled
  335.      */
  336.     protected boolean isRootPaneCheckingEnabled() {
  337.         return rootPaneCheckingEnabled;
  338.     }
  339.  
  340.  
  341.     /**
  342.      * If true then calls to add() and setLayout() will cause an exception
  343.      * to be thrown.  
  344.      *
  345.      * @see #addImpl
  346.      * @see #setLayout
  347.      * @see #isRootPaneCheckingEnabled
  348.      * @beaninfo
  349.      *   hidden: true
  350.      * description: Whether the add and setLayout methods throw exceptions when invoked.
  351.      */
  352.     protected void setRootPaneCheckingEnabled(boolean enabled) {
  353.         rootPaneCheckingEnabled = enabled;
  354.     }
  355.  
  356.     /**
  357.      * Create an runtime exception with a message like:
  358.      * <pre>
  359.      * "Do not use JDialog.add() use JDialog.getContentPane().add() instead"
  360.      * </pre>
  361.      */
  362.     private Error createRootPaneException(String op) {
  363.         String type = getClass().getName();
  364.         return new Error(
  365.             "Do not use " + type + "." + op + "() use " 
  366.                           + type + ".getContentPane()." + op + "() instead");
  367.     }
  368.  
  369.  
  370.     /**
  371.      * By default, children may not be added directly to a this component,
  372.      * they must be added to its contentPane instead.  For example:
  373.      * <pre>
  374.      * thisComponent.getContentPane().add(child)
  375.      * </pre>
  376.      * An attempt to add to directly to this component will cause an
  377.      * runtime exception to be thrown.  Subclasses can disable this
  378.      * behavior.
  379.      * 
  380.      * @see #setRootPaneCheckingEnabled
  381.      * @exception Error if called with rootPaneChecking true
  382.      */
  383.     protected void addImpl(Component comp, Object constraints, int index) 
  384.     {
  385.         if(isRootPaneCheckingEnabled()) {
  386.             throw createRootPaneException("add");
  387.         }
  388.         else {
  389.             super.addImpl(comp, constraints, index);
  390.         }
  391.     }
  392.  
  393.  
  394.     /**
  395.      * By default the layout of this component may not be set,
  396.      * the layout of its contentPane should be set instead.  
  397.      * For example:
  398.      * <pre>
  399.      * thisComponent.getContentPane().setLayout(new BorderLayout())
  400.      * </pre>
  401.      * An attempt to set the layout of this component will cause an
  402.      * runtime exception to be thrown.  Subclasses can disable this
  403.      * behavior.
  404.      * 
  405.      * @see #setRootPaneCheckingEnabled
  406.      * @exception Error if called with rootPaneChecking true
  407.      */
  408.     public void setLayout(LayoutManager manager) {
  409.         if(isRootPaneCheckingEnabled()) {
  410.             throw createRootPaneException("setLayout");
  411.         }
  412.         else {
  413.             super.setLayout(manager);
  414.         }
  415.     }
  416.  
  417.  
  418.     /**
  419.      * Returns the rootPane object for this dialog.
  420.      *
  421.      * @see #setRootPane
  422.      * @see RootPaneContainer#getRootPane
  423.      */
  424.     public JRootPane getRootPane() { 
  425.         return rootPane; 
  426.     }
  427.  
  428.  
  429.     /**
  430.      * Sets the rootPane property.  This method is called by the constructor.
  431.      * @param root the rootPane object for this dialog
  432.      *
  433.      * @see #getRootPane
  434.      *
  435.      * @beaninfo
  436.      *   hidden: true
  437.      * description: the RootPane object for this dialog.
  438.      */
  439.     protected void setRootPane(JRootPane root) {
  440.         if(rootPane != null) {
  441.             remove(rootPane);
  442.         }
  443.         rootPane = root;
  444.         if(rootPane != null) {
  445.             boolean checkingEnabled = isRootPaneCheckingEnabled();
  446.             try {
  447.                 setRootPaneCheckingEnabled(false);
  448.                 add(rootPane, BorderLayout.CENTER);
  449.             }
  450.             finally {
  451.                 setRootPaneCheckingEnabled(checkingEnabled);
  452.             }
  453.         }
  454.     }
  455.  
  456.  
  457.     /**
  458.      * Returns the contentPane object for this dialog.
  459.      *
  460.      * @see #setContentPane
  461.      * @see RootPaneContainer#getContentPane
  462.      */
  463.     public Container getContentPane() { 
  464.         return getRootPane().getContentPane(); 
  465.     }
  466.  
  467.  
  468.    /**
  469.      * Sets the contentPane property.  This method is called by the constructor.
  470.      * @param contentPane the contentPane object for this dialog
  471.      *
  472.      * @exception java.awt.IllegalComponentStateException (a runtime
  473.      *            exception) if the content pane parameter is null
  474.      * @see #getContentPane
  475.      * @see RootPaneContainer#setContentPane
  476.      *
  477.      * @beaninfo
  478.      *     hidden: true
  479.      *     description: The client area of the dialog where child 
  480.      *                  components are normally inserted.
  481.      */
  482.     public void setContentPane(Container contentPane) {
  483.         getRootPane().setContentPane(contentPane);
  484.     }
  485.  
  486.     /**
  487.      * Returns the layeredPane object for this dialog.
  488.      *
  489.      * @see #setLayeredPane
  490.      * @see RootPaneContainer#getLayeredPane
  491.      */
  492.     public JLayeredPane getLayeredPane() { 
  493.         return getRootPane().getLayeredPane(); 
  494.     }
  495.  
  496.     /**
  497.      * Sets the layeredPane property.  This method is called by the constructor.
  498.      * @param layeredPane the layeredPane object for this dialog
  499.      *
  500.      * @exception java.awt.IllegalComponentStateException (a runtime
  501.      *            exception) if the layered pane parameter is null
  502.      * @see #getLayeredPane
  503.      * @see RootPaneContainer#setLayeredPane
  504.      *
  505.      * @beaninfo
  506.      *     hidden: true
  507.      *     description: The pane which holds the various dialog layers.
  508.      */
  509.     public void setLayeredPane(JLayeredPane layeredPane) {
  510.         getRootPane().setLayeredPane(layeredPane);
  511.     }
  512.  
  513.     /**
  514.      * Returns the glassPane object for this dialog.
  515.      *
  516.      * @see #setGlassPane
  517.      * @see RootPaneContainer#getGlassPane
  518.      */
  519.     public Component getGlassPane() { 
  520.         return getRootPane().getGlassPane(); 
  521.     }
  522.  
  523.     /**
  524.      * Sets the glassPane property. 
  525.      * This method is called by the constructor.
  526.      * @param glassPane the glassPane object for this dialog
  527.      * @see #getGlassPane
  528.      * @see RootPaneContainer#setGlassPane
  529.      *
  530.      * @beaninfo
  531.      *     hidden: true
  532.      *     description: A transparent pane used for menu rendering.
  533.      */
  534.     public void setGlassPane(Component glassPane) {
  535.         getRootPane().setGlassPane(glassPane);
  536.     }
  537.  
  538.  
  539.     /**
  540.      * Sets the location of the dialog relative to the specified
  541.      * component. If the component is not currently showing, the 
  542.      * dialog is centered on the screen.
  543.      *
  544.      * @param c  the component in relation to which the dialog's location
  545.      *           is determined
  546.      */
  547.     public void setLocationRelativeTo(Component c) {
  548.         Container root=null;
  549.  
  550.         if (c != null) {
  551.             if (c instanceof Window || c instanceof Applet) {
  552.                root = (Container)c;
  553.             } else {
  554.                 Container parent;
  555.                 for(parent = c.getParent() ; parent != null ; parent = parent.getParent()) {
  556.                     if (parent instanceof Window || parent instanceof Applet) {
  557.                         root = parent;
  558.                         break;
  559.                     }
  560.                 }
  561.             }
  562.         }
  563.  
  564.         if((c != null && !c.isShowing()) || root == null ||
  565.            !root.isShowing()) {
  566.             Dimension         paneSize = getSize();
  567.             Dimension         screenSize = getToolkit().getScreenSize();
  568.  
  569.             setLocation((screenSize.width - paneSize.width) / 2,
  570.                         (screenSize.height - paneSize.height) / 2);
  571.         } else {
  572.             Dimension           invokerSize = c.getSize();
  573.             Point               invokerScreenLocation = c.getLocationOnScreen();
  574.             Rectangle           dialogBounds = getBounds();
  575.             int                 dx = invokerScreenLocation.x+((invokerSize.width-dialogBounds.width)>>1);
  576.             int                 dy = invokerScreenLocation.y+((invokerSize.height - dialogBounds.height)>>1);
  577.             Dimension           ss = getToolkit().getScreenSize();
  578.  
  579.             if (dy+dialogBounds.height>ss.height) {
  580.                 dy = ss.height-dialogBounds.height;
  581.                 dx = invokerScreenLocation.x<(ss.width>>1) ? invokerScreenLocation.x+invokerSize.width :
  582.                     invokerScreenLocation.x-dialogBounds.width;
  583.             }
  584.             if (dx+dialogBounds.width>ss.width) dx = ss.width-dialogBounds.width;
  585.             if (dx<0) dx = 0;
  586.             if (dy<0) dy = 0;
  587.             setLocation(dx, dy);
  588.         }
  589.     }
  590.  
  591.  
  592.     /**
  593.      * Returns a string representation of this JDialog. This method 
  594.      * is intended to be used only for debugging purposes, and the 
  595.      * content and format of the returned string may vary between      
  596.      * implementations. The returned string may be empty but may not 
  597.      * be <code>null</code>.
  598.      * <P>
  599.      * Overriding paramString() to provide information about the
  600.      * specific new aspects of the JFC components.
  601.      * 
  602.      * @return  a string representation of this JDialog.
  603.      */
  604.     protected String paramString() {
  605.         String defaultCloseOperationString;
  606.         if (defaultCloseOperation == HIDE_ON_CLOSE) {
  607.             defaultCloseOperationString = "HIDE_ON_CLOSE";
  608.         } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
  609.             defaultCloseOperationString = "DISPOSE_ON_CLOSE";
  610.         } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
  611.             defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
  612.         } else defaultCloseOperationString = "";
  613.     String rootPaneString = (rootPane != null ?
  614.                  rootPane.toString() : "");
  615.     String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
  616.                         "true" : "false");
  617.  
  618.     return super.paramString() +
  619.     ",defaultCloseOperation=" + defaultCloseOperationString +
  620.     ",rootPane=" + rootPaneString +
  621.     ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
  622.     }
  623.  
  624.  
  625. /////////////////
  626. // Accessibility support
  627. ////////////////
  628.  
  629.     protected AccessibleContext accessibleContext = null;
  630.  
  631.     /**
  632.      * Get the AccessibleContext associated with this JDialog
  633.      *
  634.      * @return the AccessibleContext of this JDialog
  635.      */
  636.     public AccessibleContext getAccessibleContext() {
  637.         if (accessibleContext == null) {
  638.             accessibleContext = new AccessibleJDialog();
  639.         }
  640.         return accessibleContext;
  641.     }
  642.  
  643.     /**
  644.      * The class used to obtain the AccessibleRole for this object.
  645.      */
  646.     protected class AccessibleJDialog extends AccessibleContext 
  647.         implements Serializable, AccessibleComponent {
  648.  
  649.         
  650.         // AccessibleContext methods
  651.         //
  652.         /**
  653.          * Get the accessible name of this object.  
  654.          *
  655.          * @return the localized name of the object -- can be null if this 
  656.          * object does not have a name
  657.          */
  658.         public String getAccessibleName() {
  659.             if (accessibleName != null) {
  660.                 return accessibleName;
  661.             } else {
  662.                 if (getTitle() == null) {
  663.                     return super.getAccessibleName();
  664.                 } else {
  665.                     return getTitle();
  666.                 }
  667.             }
  668.         }
  669.  
  670.         /**
  671.          * Get the role of this object.
  672.          *
  673.          * @return an instance of AccessibleRole describing the role of the 
  674.          * object
  675.          * @see AccessibleRole
  676.          */
  677.         public AccessibleRole getAccessibleRole() {
  678.             return AccessibleRole.DIALOG;
  679.         }
  680.  
  681.         /**
  682.          * Get the state of this object.
  683.          *
  684.          * @return an instance of AccessibleStateSet containing the current 
  685.          * state set of the object
  686.          * @see AccessibleState
  687.          */
  688.         public AccessibleStateSet getAccessibleStateSet() {
  689.             AccessibleStateSet states = SwingUtilities.getAccessibleStateSet(JDialog.this);
  690.             if (isResizable()) {
  691.                 states.add(AccessibleState.RESIZABLE);
  692.             }
  693.             if (getFocusOwner() != null) {
  694.                 states.add(AccessibleState.ACTIVE);
  695.             }
  696.             if (isModal()) {
  697.                 states.add(AccessibleState.MODAL);
  698.             }
  699.             return states;
  700.         }
  701.  
  702.         /**
  703.          * Get the Accessible parent of this object.  If the parent of this
  704.          * object implements Accessible, this method should simply return
  705.          * getParent().
  706.          *
  707.          * @return the Accessible parent of this object -- can be null if this
  708.          * object does not have an Accessible parent
  709.          */
  710.         public Accessible getAccessibleParent() {
  711.         if (accessibleParent != null) {
  712.         return accessibleParent;
  713.         } else {
  714.                 Container parent = getParent();
  715.                 if (parent instanceof Accessible) {
  716.                     return (Accessible) parent;
  717.         }
  718.             }
  719.             return null;
  720.         }
  721.  
  722.         /**
  723.          * Get the index of this object in its accessible parent. 
  724.          *
  725.          * @return the index of this object in its parent; -1 if this 
  726.          * object does not have an accessible parent.
  727.          * @see #getAccessibleParent
  728.          */
  729.         public int getAccessibleIndexInParent() {
  730.             return SwingUtilities.getAccessibleIndexInParent(JDialog.this);
  731.         }
  732.  
  733.         /**
  734.          * Returns the number of accessible children in the object.  If all
  735.          * of the children of this object implement Accessible, than this
  736.          * method should return the number of children of this object.
  737.          *
  738.          * @return the number of accessible children in the object.
  739.          */
  740.         public int getAccessibleChildrenCount() {
  741.             return SwingUtilities.getAccessibleChildrenCount(JDialog.this);
  742.         }
  743.  
  744.         /**
  745.          * Return the nth Accessible child of the object.  
  746.          *
  747.          * @param i zero-based index of child
  748.          * @return the nth Accessible child of the object
  749.          */
  750.         public Accessible getAccessibleChild(int i) {
  751.             return SwingUtilities.getAccessibleChild(JDialog.this,i);
  752.         }
  753.  
  754.         /**
  755.          * Return the locale of this object.
  756.          *
  757.          * @return the locale of this object
  758.          */
  759.         public Locale getLocale() {
  760.             return JDialog.this.getLocale();
  761.         }
  762.  
  763.         /**
  764.          * Get the AccessibleComponent associated with this object if one
  765.          * exists.  Otherwise return null.
  766.          */
  767.         public AccessibleComponent getAccessibleComponent() {
  768.             return this;
  769.         }
  770.  
  771.  
  772.         // AccessibleComponent methods
  773.         //
  774.         /**
  775.          * Get the background color of this object.
  776.          *
  777.          * @return the background color, if supported, of the object; 
  778.          * otherwise, null
  779.          */
  780.         public Color getBackground() {
  781.             return JDialog.this.getBackground();
  782.         }
  783.  
  784.         /**
  785.          * Set the background color of this object.
  786.          *
  787.          * @param c the new Color for the background
  788.          */
  789.         public void setBackground(Color c) {
  790.             JDialog.this.setBackground(c);
  791.         }
  792.  
  793.         /**
  794.          * Get the foreground color of this object.
  795.          *
  796.          * @return the foreground color, if supported, of the object; 
  797.          * otherwise, null
  798.          */
  799.         public Color getForeground() {
  800.             return JDialog.this.getForeground();
  801.         }
  802.  
  803.         /**
  804.          * Set the foreground color of this object.
  805.          *
  806.          * @param c the new Color for the foreground
  807.          */
  808.         public void setForeground(Color c) {
  809.             JDialog.this.setForeground(c);
  810.         }
  811.  
  812.         /**
  813.          * Get the Cursor of this object.
  814.          *
  815.          * @return the Cursor, if supported, of the object; otherwise, null
  816.          */
  817.         public Cursor getCursor() {
  818.             return JDialog.this.getCursor();
  819.         }
  820.  
  821.         /**
  822.          * Set the Cursor of this object.
  823.          *
  824.          * @param c the new Cursor for the object
  825.          */
  826.         public void setCursor(Cursor cursor) {
  827.             JDialog.this.setCursor(cursor);
  828.         }
  829.  
  830.         /**
  831.          * Get the Font of this object.
  832.          *
  833.          * @return the Font,if supported, for the object; otherwise, null
  834.          */
  835.         public Font getFont() {
  836.             return JDialog.this.getFont();
  837.         }
  838.  
  839.         /**
  840.          * Set the Font of this object.
  841.          *
  842.          * @param f the new Font for the object
  843.          */
  844.         public void setFont(Font f) {
  845.             JDialog.this.setFont(f);
  846.         }
  847.  
  848.         /**
  849.          * Get the FontMetrics of this object.
  850.          *
  851.          * @param f the Font
  852.          * @return the FontMetrics, if supported, the object; otherwise, null
  853.          * @see getFont
  854.          */
  855.         public FontMetrics getFontMetrics(Font f) {
  856.             return JDialog.this.getFontMetrics(f);
  857.         }
  858.  
  859.         /**
  860.          * Determine if the object is enabled.
  861.          *
  862.          * @return true if object is enabled; otherwise, false
  863.          */
  864.         public boolean isEnabled() {
  865.             return JDialog.this.isEnabled();
  866.         }
  867.  
  868.         /**
  869.          * Set the enabled state of the object.
  870.          *
  871.          * @param b if true, enables this object; otherwise, disables it 
  872.          */
  873.         public void setEnabled(boolean b) {
  874.             JDialog.this.setEnabled(b);
  875.         }
  876.         
  877.         /**
  878.          * Determine if the object is visible.  Note: this means that the
  879.          * object intends to be visible; however, it may not in fact be
  880.          * showing on the screen because one of the objects that this object
  881.          * is contained by is not visible.  To determine if an object is
  882.          * showing on the screen, use isShowing().
  883.          *
  884.          * @return true if object is visible; otherwise, false
  885.          */
  886.         public boolean isVisible() {
  887.             return JDialog.this.isVisible();
  888.         }
  889.  
  890.         /**
  891.          * Set the visible state of the object.
  892.          *
  893.          * @param b if true, shows this object; otherwise, hides it 
  894.          */
  895.         public void setVisible(boolean b) {
  896.             JDialog.this.setVisible(b);
  897.         }
  898.  
  899.         /**
  900.          * Determine if the object is showing. This is determined by checking
  901.          * the visibility of the object and ancestors of the object.  Note: 
  902.          * this will return true even if the object is obscured by another 
  903.          * (for example, it happens to be underneath a menu that was pulled 
  904.          * down).
  905.          *
  906.          * @return true if object is showing; otherwise, false
  907.          */
  908.         public boolean isShowing() {
  909.             return JDialog.this.isShowing();
  910.         }
  911.  
  912.         /** 
  913.          * Checks whether the specified point is within this object's bounds,
  914.          * where the point's x and y coordinates are defined to be relative to 
  915.          * the coordinate system of the object. 
  916.          *
  917.          * @param p the Point relative to the coordinate system of the object
  918.          * @return true if object contains Point; otherwise false
  919.          */
  920.         public boolean contains(Point p) {
  921.             return JDialog.this.contains(p);
  922.         }
  923.     
  924.         /** 
  925.          * Returns the location of the object on the screen.
  926.          *
  927.          * @return location of object on screen -- can be null if this object
  928.          * is not on the screen
  929.          */
  930.         public Point getLocationOnScreen() {
  931.             return JDialog.this.getLocationOnScreen();
  932.         }
  933.  
  934.         /** 
  935.          * Gets the location of the object relative to the parent in the form 
  936.          * of a point specifying the object's top-left corner in the screen's 
  937.          * coordinate space.
  938.          *
  939.          * @return An instance of Point representing the top-left corner of 
  940.          * the objects's bounds in the coordinate space of the screen; null if
  941.          * this object or its parent are not on the screen
  942.          */
  943.         public Point getLocation() {
  944.             return JDialog.this.getLocation();
  945.         }
  946.  
  947.         /** 
  948.          * Sets the location of the object relative to the parent.
  949.          */
  950.         public void setLocation(Point p) {
  951.             JDialog.this.setLocation(p);
  952.         }
  953.  
  954.         /** 
  955.          * Gets the bounds of this object in the form of a Rectangle object. 
  956.          * The bounds specify this object's width, height, and location
  957.          * relative to its parent. 
  958.          *
  959.          * @return A rectangle indicating this component's bounds; null if 
  960.          * this object is not on the screen.
  961.          */
  962.         public Rectangle getBounds() {
  963.             return JDialog.this.getBounds();
  964.         }
  965.  
  966.         /** 
  967.          * Sets the bounds of this object in the form of a Rectangle object. 
  968.          * The bounds specify this object's width, height, and location
  969.          * relative to its parent.
  970.          *      
  971.          * @param A rectangle indicating this component's bounds
  972.          */
  973.         public void setBounds(Rectangle r) {
  974.             JDialog.this.setBounds(r);
  975.         }
  976.  
  977.         /** 
  978.          * Returns the size of this object in the form of a Dimension object. 
  979.          * The height field of the Dimension object contains this objects's
  980.          * height, and the width field of the Dimension object contains this 
  981.          * object's width. 
  982.          *
  983.          * @return A Dimension object that indicates the size of this 
  984.          * component; null if this object is not on the screen
  985.          */
  986.         public Dimension getSize() {
  987.             return JDialog.this.getSize();
  988.         }
  989.  
  990.         /** 
  991.          * Resizes this object so that it has width width and height. 
  992.          *      
  993.          * @param d - The dimension specifying the new size of the object. 
  994.          */
  995.         public void setSize(Dimension d) {
  996.             JDialog.this.setSize(d);
  997.         }
  998.  
  999.         /**
  1000.          * Returns the Accessible child, if one exists, contained at the local
  1001.          * coordinate Point.
  1002.          *
  1003.          * @param p The point defining the top-left corner of the Accessible, 
  1004.          * given in the coordinate space of the object's parent. 
  1005.          * @return the Accessible, if it exists, at the specified location; 
  1006.          * else null
  1007.          */
  1008.         public Accessible getAccessibleAt(Point p) {
  1009.             return SwingUtilities.getAccessibleAt(JDialog.this,p);
  1010.         }
  1011.  
  1012.         /**
  1013.          * Returns whether this object can accept focus or not.
  1014.          *
  1015.          * @return true if object can accept focus; otherwise false
  1016.          */
  1017.         public boolean isFocusTraversable() {
  1018.             return JDialog.this.isFocusTraversable();
  1019.         }
  1020.  
  1021.         /**
  1022.          * Requests focus for this object.
  1023.          */
  1024.         public void requestFocus() {
  1025.             JDialog.this.requestFocus();
  1026.         }
  1027.  
  1028.         /**
  1029.          * Adds the specified focus listener to receive focus events from this 
  1030.          * component. 
  1031.          *
  1032.          * @param l the focus listener
  1033.          */
  1034.         public void addFocusListener(FocusListener l) {
  1035.             JDialog.this.addFocusListener(l);
  1036.         }
  1037.  
  1038.         /**
  1039.          * Removes the specified focus listener so it no longer receives focus 
  1040.          * events from this component.
  1041.          *
  1042.          * @param l the focus listener
  1043.          */
  1044.         public void removeFocusListener(FocusListener l) {
  1045.             JDialog.this.removeFocusListener(l);
  1046.         }
  1047.     } // inner class AccessibleJDialog
  1048. }
  1049.